﻿using Zero;

/// <summary>
/// 元素反应：燃烧
/// </summary>
public class ElementBurning : IElementReaction
{
    private readonly IElementHolder _holder;
    private readonly IElementAura _burningAura;

    public ElementBurning(IElementHolder holder)
    {
        _holder = holder;
        _burningAura = holder.GetElementAura("燃烧");
    }

    public void Reaction(TriggerElementData triggerElementData)
    {
        if (_burningAura.Gauge > 0f)
        {
            if (triggerElementData.ElementType is ElementType.Grass or ElementType.Fire)
            {
                _burningAura.Source = triggerElementData.Source;
            }
        }
        else
        {
            if (_holder.GetElementAura("火").Gauge > 0f && triggerElementData.ElementType == ElementType.Grass ||
                _holder.GetGeneralElementAura(ElementType.Grass).Gauge > 0f && triggerElementData.ElementType == ElementType.Fire)
            {
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "燃烧");
                _burningAura.Attach(2f, triggerElementData.Source);
            }
        }
    }
}